import { getUserInfo } from "~/api/user"; //为了获取审核员姓名

import { getOrderInfo, getFinalsOrderInfo ,closeOrder, uploadSH } from "~/api/order"; //结束流程

function getOrderInfoFn(axios, order, that) {
    getOrderInfo(axios, order)
        .then(({ data }) => {
            if (data.status == "success") {
                that.form = data.data;
				that.form.opinions = that.form.opinions.reverse()
                if (that.form.pattern == 1) {
                    that.form.pattern = "idea模式";
                } else if (that.form.pattern == "2") {
                    that.form.pattern = "技术交底模式";
                } else if (that.form.pattern == "3") {
                    that.form.pattern = "定向导航";
                }
                if (that.form.service == "N") {
                    that.form.service = "普通模式";
                } else if (that.form.service == "Q") {
                    that.form.service = "急速模式";
                } else if (that.form.service == "A") {
                    that.form.service = "授权模式";
                } else if (that.form.service == "QA") {
                    that.form.service = "双选(急速授权模式)";
                }
                //获取审核员姓名
                // if (that.form.auditor_id != null) {
                //     getUserInfo(axios, that.form.auditor_id)
                //         .then(({ data }) => {
                //             if (data.status == "success") {
                //                 that.form.auditor_name = data.data.name;
                //             }
                //         })
                //         .catch(err => {
                //             console.log(err);
                //         })
                // }

                // 审核文件切分成数组
                if (that.form.review_file == null || that.form.review_file == "") {} else {
                    let fileArr = that.form.review_file.split("&");
                    that.form.reviewfileArr = [];
                    for (const i in fileArr) {
                        let itemobj = {
                            id: i + 1,
                            path: fileArr[i],
                            file: ''
                        };
                        let itemArr = itemobj.path.split("/")
                        itemobj.path = itemArr[itemArr.length - 1]
                        itemobj.file = itemArr.slice(0, 2).join("/");
                        that.form.reviewfileArr.push(itemobj);
                    }
                }

                // 撤案申请文件
                if (that.form.reason_file == null || that.form.reason_file == "") {} else {
                    let reasonfileArr = that.form.reason_file.split("&");
                    that.form.reasonfileArr = [];
                    for (const i in reasonfileArr) {
                        let itemobj = {
                            id: i + 1,
                            path: reasonfileArr[i],
                            file: ''
                        };
                        let itemArr = itemobj.path.split("/")
                        itemobj.path = itemArr[itemArr.length - 1]
                        itemobj.file = itemArr.slice(0, 2).join("/");
                        that.form.reasonfileArr.push(itemobj);
                    }
                }

                //已完成文件 切分组件
                if (that.form.fish_file == null || that.form.fish_file == "") {} else {
                    let fishfileArr = that.form.fish_file.split("&");
                    that.form.fishfileArr = [];
                    for (const i in fishfileArr) {
                        let itemobj = {
                            id: i + 1,
                            path: fishfileArr[i],
                            file: ''
                        };
                        let itemArr = itemobj.path.split("/")
                        itemobj.path = itemArr[itemArr.length - 1]
                        itemobj.file = itemArr.slice(0, 2).join("/");
                        that.form.fishfileArr.push(itemobj);
                    }
                }
                //图片 切分组件
                if (that.form.thumb_imgs == null || that.form.thumb_imgs == "") {} else {
                    let img_Arr = that.form.thumb_imgs.split("&");
                    let img_Arr2 = that.form.img.split('&')
                    that.form.imgArr = [];
                    that.form.imgList = [];
                    that.form.imgList2 = []
                    for (const i in img_Arr2) {
                        that.form.imgList2.push(global.baseurl + '/storage/upload/' + img_Arr2[i])
                    }
                    for (const i in img_Arr) {
                        let itemobj = {
                            id: i + 1,
                            path: img_Arr[i],
                            file: ''
                        };
                        that.form.imgList.push(global.baseurl + '/storage/upload/' + img_Arr[i])
                        let itemArr = itemobj.path.split("/")
                        itemobj.path = itemArr[itemArr.length - 1]
                        itemobj.file = itemArr.slice(0, 2).join("/");
                        that.form.imgArr.push(itemobj);
                    }
                }

                //文件 切分组件
                if (that.form.file == null || that.form.file == "") {} else {
                    let file_Arr = that.form.file.split("&");
                    that.form.fileArr = [];
                    for (const i in file_Arr) {
                        let itemobj = {
                            id: i + 1,
                            path: file_Arr[i],
                            file: ''
                        };
                        let itemArr = itemobj.path.split("/")
                        itemobj.path = itemArr[itemArr.length - 1]
                        itemobj.file = itemArr.slice(0, 2).join("/");
                        that.form.fileArr.push(itemobj);
                    }
                }
                if (that.form.student_review_file == null || that.form.student_review_file == "") {} else {
                    let file_Arr = that.form.student_review_file.split("&");
                    that.form.studentFile = [];
                    for (const i in file_Arr) {
                        let itemobj = {
                            id: i + 1,
                            path: file_Arr[i],
                            file: ''
                        };
                        let itemArr = itemobj.path.split("/")
                        itemobj.path = itemArr[itemArr.length - 1]
                        itemobj.file = itemArr.slice(0, 2).join("/");
                        that.form.studentFile.push(itemobj);
                    }
                }

                // 操作options

                //倒转数组
                that.formLen = that.form.opinions.length;

                if (that.form.opinions.length == 0 && that.form.teacher_opinions.length == 0) {
                    that.form.allOpinions = null
                } else {
                    that.form.opinions.reverse();
                    that.form.teacher_opinions.reverse();
                    that.form.opinions.forEach(v => {
                        v.from = '审核员'
                        v.time_code = Date.parse(new Date(v.created_at))
                    })
                    that.form.teacher_opinions.forEach(v => {
                        v.from = '导师'
                        v.time_code = Date.parse(new Date(v.created_at))
                    })
                    that.form.allOpinions = that.form.opinions.concat(that.form.teacher_opinions)
                    that.form.allOpinions.sort((a, b) => a.time_code < b.time_code ? 1 : -1)
                    console.log(that.form.allOpinions)
                }
                that.activeNum = that.form.opinions.length;
            } else {
                that.dialogVisible = false;
                that.$message({
                    type: "error",
                    message: data.message
                });
            }
        })
        .catch(err => {
            console.log(err)
            that.$message({
                type: "error",
                message: err
            });
        });
}
function getFinalsOrderInfoShow(axios, order, that) {
    getFinalsOrderInfo(axios, order)
        .then(({ data }) => {
            if (data.status == "success") {
                that.form = data.data;
				// that.form.opinions = that.form.opinions.reverse()
                // if (that.form.pattern == 1) {
                //     that.form.pattern = "idea模式";
                // } else if (that.form.pattern == "2") {
                //     that.form.pattern = "技术交底模式";
                // } else if (that.form.pattern == "3") {
                //     that.form.pattern = "定向导航";
                // }
                // if (that.form.service == "N") {
                //     that.form.service = "普通模式";
                // } else if (that.form.service == "Q") {
                //     that.form.service = "急速模式";
                // } else if (that.form.service == "A") {
                //     that.form.service = "授权模式";
                // } else if (that.form.service == "QA") {
                //     that.form.service = "双选(急速授权模式)";
                // }
                //获取审核员姓名
                if (that.form.auditor_id != null) {
                    getUserInfo(axios, that.form.auditor_id)
                        .then(({ data }) => {
                            if (data.status == "success") {
                                that.form.auditor_name = data.data.name;
                            }
                        })
                        .catch(err => {
                            console.log(err);
                        });
                }

                // 审核文件切分成数组
                if (that.form.review_file == null || that.form.review_file == "") {} else {
                    let fileArr = that.form.review_file.split("&");
                    that.form.reviewfileArr = [];
                    for (const i in fileArr) {
                        let itemobj = {
                            id: i + 1,
                            path: fileArr[i],
                            file: ''
                        };
                        let itemArr = itemobj.path.split("/")
                        itemobj.path = itemArr[itemArr.length - 1]
                        itemobj.file = itemArr.slice(0, 2).join("/");
                        that.form.reviewfileArr.push(itemobj);
                    }
                }

                //已完成文件 切分组件
                if (that.form.fish_file == null || that.form.fish_file == "") {} else {
                    let fishfileArr = that.form.fish_file.split("&");
                    that.form.fishfileArr = [];
                    for (const i in fishfileArr) {
                        let itemobj = {
                            id: i + 1,
                            path: fishfileArr[i],
                            file: ''
                        };
                        let itemArr = itemobj.path.split("/")
                        itemobj.path = itemArr[itemArr.length - 1]
                        itemobj.file = itemArr.slice(0, 2).join("/");
                        that.form.fishfileArr.push(itemobj);
                    }
                }


                //图片 切分组件
                if (that.form.img == null || that.form.img == "") {} else {
                    let img_Arr = that.form.img.split("&");
                    that.form.imgArr = [];
                    for (const i in img_Arr) {
                        let itemobj = {
                            id: i + 1,
                            path: img_Arr[i],
                            file: ''
                        };
                        let itemArr = itemobj.path.split("/")
                        itemobj.path = itemArr[itemArr.length - 1]
                        itemobj.file = itemArr.slice(0, 2).join("/");
                        that.form.imgArr.push(itemobj);
                    }
                }

                //文件 切分组件
                if (that.form.file == null || that.form.file == "") {} else {
                    let file_Arr = that.form.file.split("&");
                    that.form.fileArr = [];
                    for (const i in file_Arr) {
                        let itemobj = {
                            id: i + 1,
                            path: file_Arr[i],
                            file: ''
                        };
                        let itemArr = itemobj.path.split("/")
                        itemobj.path = itemArr[itemArr.length - 1]
                        itemobj.file = itemArr.slice(0, 2).join("/");
                        that.form.fileArr.push(itemobj);
                    }
                }


            } else {
                that.dialogVisible = false;
                that.$message({
                    type: "error",
                    message: data.message
                });
            }
        })
        .catch(err => {
            that.$message({
                type: "error",
                message: err
            });
        });
}

export default {
    getOrderInfoFn,
    getFinalsOrderInfoShow
}
